use reqwest::header::{self, HeaderMap};
use std::{sync::Arc, time::Duration};

pub fn create_client(proxy: Option<String>) -> Result<reqwest::Client, reqwest::Error> {
    if proxy.is_some() {
        println!("{:?}", proxy);

        let client_proxy = reqwest::Url::parse(proxy.as_ref().unwrap()).unwrap();
        let addr = format!(
            "http://{}:{}",
            client_proxy.host_str().unwrap(),
            client_proxy.port().unwrap(),
        );

        let proxy_ = reqwest::Proxy::all(addr)
            .unwrap()
            .basic_auth(client_proxy.username(), client_proxy.password().unwrap());

        return reqwest::Client::builder()
            .cookie_store(true)
            .proxy(proxy_)
            .build();
    }

    reqwest::Client::builder()
        .cookie_store(true)
        // .timeout(Some(Duration::from_secs(5)))
        .build()
}
